//
//  MyCityViewController.m
//  1gene
//
//  Created by 1jiyin on 16/4/11.
//  Copyright © 2016年 1jiyin. All rights reserved.
//

#import "MyCityViewController.h"
#import "GoodsAddressDetailViewController.h"
#import "XianViewController.h"
@interface MyCityViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation MyCityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:[UIView new]];
    [self createNavigation];
    [self createUI];
    // Do any additional setup after loading the view.
}
-(void)createUI
{
    UITableView *table=[[UITableView alloc]initWithFrame:CGRectMake(0, 20+44, self.view.frame.size.width, self.view.frame.size.height-44-20) style:UITableViewStylePlain];
    table.delegate=self;
    table.dataSource=self;
    table.tableHeaderView=[UIView new];
    table.tableFooterView=[UIView new];
    table.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:table];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    for (id subView in cell.contentView.subviews) {
        [subView removeFromSuperview];
    }
    UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(5, 0, self.view.frame.size.width-5, 40-1)];
    lab.text=_arr[indexPath.row][@"name"];
    lab.textColor=[UIColor blackColor];
    lab.font=[UIFont systemFontOfSize:16];
    [cell.contentView addSubview:lab];
    
    UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, 39, self.view.frame.size.width, 1)];
    line.backgroundColor=[UIColor grayColor];
    [cell.contentView addSubview:line];
    
    
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    XianViewController *xianViewController = [XianViewController new];
    xianViewController.province=_province;
    xianViewController.city=_arr[indexPath.row][@"name"];
    xianViewController.dataArray=[NSArray arrayWithArray:_arr[indexPath.row][@"area"]];
    xianViewController.myState=_myState;
    [self.navigationController pushViewController:xianViewController animated:YES];
    
    
    
//    self.navigationController.navigationBar.hidden=YES;
//    UIViewController *target = nil;
//    
//    if (_myState==1) {
//        GoodsAddressDetailViewController *homeVC=[GoodsAddressDetailViewController new];
//        for (UIViewController * controller in self.navigationController.viewControllers) { //遍历
//            if ([controller isKindOfClass:[homeVC class]]) { //这里判断是否为你想要跳转的页面
//                target = controller;
//            }
//        }
//    }else{
//            ChangeBaseMessageViewController *homeVC = [[ChangeBaseMessageViewController alloc] init];
//        for (UIViewController * controller in self.navigationController.viewControllers) { //遍历
//            if ([controller isKindOfClass:[homeVC class]]) { //这里判断是否为你想要跳转的页面
//                target = controller;
//            }
//        }
//    }
//
//   
//
//    if (target) {
//        [[NSNotificationCenter defaultCenter]postNotificationName:@"myChangeCity" object:nil userInfo:@{@"city":_arr[indexPath.row],@"province":_province}];
//        [self.navigationController popToViewController:target animated:YES]; //跳转
//    }
//
}





-(void)createNavigation
{
    self.navigationController.navigationBar.barTintColor=[UIColor colorWithRed:84/255.0 green:199/255.0 blue:222/255.0 alpha:1];
    //返回
    UIButton *leftBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame=CGRectMake(0, 0, 25, 25);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"left_back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    
    //标题
    UILabel *title=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
    title.text=@"地区选择";
    title.font=[UIFont systemFontOfSize:22];
    title.textAlignment=NSTextAlignmentCenter;
    title.textColor=[UIColor whiteColor];
    self.navigationItem.titleView=title;
}
//返回上一页
-(void)leftBtnClick:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden=NO;
    [self.navigationController.navigationBar setTranslucent:YES];
}
-(void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden=YES;
    [self.navigationController.navigationBar setTranslucent:NO];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
